package org.darkforest.common.services.impl;

import org.apache.commons.lang.StringUtils;
import org.darkforest.common.logger.Logger;
import org.darkforest.common.mail.MailUtil;
import org.darkforest.common.services.MessageAndNoticeService;
import org.darkforest.common.services.MobileMsgService;
import org.darkforest.common.services.WxJSSdkService;
import org.darkforest.common.util.DateUtil;
import org.darkforest.common.util.SmsSendUtil;
import org.darkforest.common.util.SystemConstant;
import org.darkforest.dao.mapper.*;
import org.darkforest.model.*;
import org.darkforest.ucenter.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * Created by abao on 2016/1/15.
 */
@Service
public class MessageAndNoticeServiceImpl implements MessageAndNoticeService {
    @Autowired
    private WxJSSdkService wxJSSdkService;
    @Autowired
    private MessageService messageService;
    @Autowired
    private MemberMsgTplMapper memberMsgTplMapper;
    @Autowired
    private StoreMapper storeMapper;
    @Autowired
    private SettingMapper settingMapper;
    @Autowired
    private MemberMapper memberMapper;
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private MobileMsgService mobileMsgService;

    public String contextRepalce(String context,String []str){
        for (int i=0;i<str.length;i++){
            context = context.replace("{"+(i+1)+"}",str[i]);
        }
        return context;
    };

    @Override
    public void sendMessageAndNotice(MemberMsgTpl memberMsgTpl, Map<String, Object> smsMap, Map<String, Object> mailMap,
                                     Map<String, Object> innerMap, Map<String, Object> wechatMap) {

        if(memberMsgTpl == null) {
            System.out.println("MemberMsgTpl == null");
            Logger.info(MessageAndNoticeServiceImpl.class,"MemberMsgTpl == null");
            return;
        }
        if((memberMsgTpl.getMmtShortSwitch() == null) && (memberMsgTpl.getMmtMailSwitch() == null) &&
                (memberMsgTpl.getMmtMessageSwitch() == null) && (memberMsgTpl.getMmtWechatSwitch() == null)) {
            System.out.println("信息发送标识都为null，信息不能够被发送");
            Logger.info(MessageAndNoticeServiceImpl.class,"信息发送标识都为null，信息不能够被发送");
            return;
        }
        if((memberMsgTpl.getMmtShortSwitch() != 1) && (memberMsgTpl.getMmtMailSwitch() != 1) &&
                (memberMsgTpl.getMmtMessageSwitch() != 1) && (memberMsgTpl.getMmtWechatSwitch() != 1)) {
            System.out.println("信息发送标识设定不正确，信息不能够被发送");
            Logger.info(MessageAndNoticeServiceImpl.class,"信息发送标识设定不正确，信息不能够被发送");
            return;
        }

        try{
            // 发送手机短信
            if((memberMsgTpl.getMmtShortSwitch() == 1) && (smsMap != null)) {
                String moblieNumber = (String)smsMap.get("moblieNumber");
                String[] params = (String[])smsMap.get("params");

                Logger.info(MessageAndNoticeServiceImpl.class,"发送手机短信:"+ moblieNumber + " 参数个数:" + params.length);

                if (StringUtils.isEmpty(moblieNumber)) {
                    System.out.println("接收短信的手机号码没有设定，短信不能够被发送");
                    Logger.info(MessageAndNoticeServiceImpl.class,"接收短信的手机号码没有设定，短信不能够被发送");
                } else if (StringUtils.isEmpty(memberMsgTpl.getMmtShortContent())) {
                    System.out.println("短信的发送内容没有设定，短信不能够被发送");
                    Logger.info(MessageAndNoticeServiceImpl.class,"短信的发送内容没有设定，短信不能够被发送");
                } else {
                    String context = contextRepalce(memberMsgTpl.getMmtShortContent(), params);
                    System.out.println("手机号【" + moblieNumber + "】的短信发送开始。短信内容为："+ context);
                    String res = mobileMsgService.sendMobileMsg(moblieNumber, context);
                    Logger.info(MessageAndNoticeServiceImpl.class,"res="+res);
                    if("true".equals(res)){
                        System.out.println("短信发送成功，moblieNumber："+ moblieNumber);
                    }else{
                        System.out.println("短信发送失败，moblieNumber："+ moblieNumber);
                    }
                }
            }

            // 发送邮件（都是没有附件的邮件）
            if((memberMsgTpl.getMmtMailSwitch() == 1) && (mailMap != null)) {
                String sender = (String)mailMap.get("sender");
                String[] receivers = (String[])mailMap.get("receivers");
                String[] titles = (String[])mailMap.get("titles");
                String[] params = (String[])mailMap.get("params");

                Logger.info(MessageAndNoticeServiceImpl.class,"发送邮件#######发送者:"+ sender + " 收件人个数:" + params.length);

                if (StringUtils.isEmpty(memberMsgTpl.getMmtMailSubject())) {
                    System.out.println("邮件的主题没有设定，邮件不能够被发送");
                } else if (StringUtils.isEmpty(memberMsgTpl.getMmtMailContent())) {
                    System.out.println("邮件的发送内容没有设定，邮件不能够被发送");
                } else {
                    if (StringUtils.isEmpty(sender)) {
                        sender = SystemConstant.USERNAME.trim();
                    }
                    if (receivers == null || receivers.length == 0) {
                        System.out.println("邮件的接收者没有设定，邮件不能够被发送");
                    } else {
                        if ("465".equals(SystemConstant.PORT.trim())) {
                            String subject = contextRepalce(memberMsgTpl.getMmtMailSubject(), titles);
                            String context = contextRepalce(memberMsgTpl.getMmtMailContent(), params);
                            String retVal = MailUtil.sendMailBySSL(subject, context, sender, receivers);
                            if ("success".equals(retVal)) {
                                System.out.println("邮件发送成功");
                            }else{
                                System.out.println("邮件发送失败");
                            }
                        } else {
                            // 25
                            MailUtil.sendMail(memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), sender, receivers);
                        }
                    }
                }
            }

            // 发送站内信
            if((memberMsgTpl.getMmtMessageSwitch() == 1) && (innerMap != null)) {
                Integer messageType = (Integer)innerMap.get("messageType");
                Member fromMember = (Member)innerMap.get("fromMember");
                Member toMember = (Member)innerMap.get("toMember");
                String[] params = (String[])innerMap.get("params");

                String context = contextRepalce(memberMsgTpl.getMmtMessageContent(), params);

                Message message = new Message();
                message.setMessageBody(context);
                message.setMessageOpen(0);
                message.setMessageState(0);
                message.setMessageParentId(0);
                message.setMessageIsmore(0);
                message.setMessageType(messageType);//0为私信、1为系统消息、2为留言
                message.setFromMemberId(fromMember.getMemberId());
                message.setFromMemberName(fromMember.getMemberName());
                message.setToMemberId(toMember.getMemberId().toString());
                message.setToMemberName(toMember.getMemberName());
                message.setMessageTime(DateUtil.unixTimeStampInt().intValue());
                messageService.insertMessage(message);
            }

            // 发送微信
            if((memberMsgTpl.getMmtWechatSwitch() == 1) && (wechatMap != null)) {
                String[] receivers = (String[])wechatMap.get("receivers");
                String[] params = (String[])wechatMap.get("params");

                if (StringUtils.isEmpty(memberMsgTpl.getMmtWechatContent())) {
                    System.out.println("微信的发送内容没有设定，微信不能够被发送");
                } else if (receivers == null || receivers.length == 0) {
                    System.out.println("微信的接收者没有设定，微信不能够被发送");
                } else {
                    for (int i = 0; i < receivers.length; i++) {
                        Integer userId = Integer.valueOf(receivers[i]);
                        Member member = memberMapper.getMemberById(userId);
                        if(member.getMemberWxOpenid() == null){
                            System.out.println("用户:" + userId +" 的微信openid没有设定，微信不能够被发送");
                        } else {
                            String context = contextRepalce(memberMsgTpl.getMmtShortContent(), params);
                            wxJSSdkService.sendWechatMessage(member.getMemberWxOpenid(), context);
                        }
                    }
                }
            }
        } catch (Exception e){
            if(memberMsgTpl.getMmtShortSwitch() == 1) {
                System.out.println("短信发送失败");
            }
            if(memberMsgTpl.getMmtMailSwitch() == 1) {
                System.out.println("邮件发送失败");
            }
            if(memberMsgTpl.getMmtMessageSwitch() == 1) {
                System.out.println("站内信发送失败");
            }
            if(memberMsgTpl.getMmtWechatSwitch() == 1) {
                System.out.println("微信发送失败");
            }

            e.printStackTrace();
            Logger.error(MessageAndNoticeServiceImpl.class, e.getLocalizedMessage());
        }
    }

    @Override
    public void setInnerMessage(String[] params,Integer MessageType,String context,Member fromMember,Member toMember) {
        try{
            context = contextRepalce(context,params);
            Message message = new Message();
            message.setMessageBody(context);
            message.setMessageOpen(0);
            message.setMessageState(0);
            message.setMessageParentId(0);
            message.setMessageIsmore(0);
            message.setMessageType(MessageType);//0为私信、1为系统消息、2为留言
            message.setFromMemberId(fromMember.getMemberId());
            message.setFromMemberName(fromMember.getMemberName());
            message.setToMemberId(toMember.getMemberId().toString());
            message.setToMemberName(toMember.getMemberName());
            message.setMessageTime(DateUtil.unixTimeStampInt().intValue());
            messageService.insertMessage(message);
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    @Override
    public void setWXMessage(String[] params,String context,Integer userId) {
        try{
            context = contextRepalce(context,params);
            Member member =memberMapper.getMemberById(userId);
            if(member.getMemberWxOpenid()!=null){
                wxJSSdkService.sendWechatMessage(member.getMemberWxOpenid(),context);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void setMailMessage(String[] titles,String[] params,String subject, String context,String email) {
        try{
            context = contextRepalce(context,params);
            subject = contextRepalce(subject,titles);
            //MailUtil.sendMail(subject, context, MailUtil.SENDER, email);
            if ("465".equals(SystemConstant.PORT.trim())) {
                MailUtil.sendMailBySSL(subject, context, SystemConstant.USERNAME.trim(), email);
            } else {
                // 25
                MailUtil.sendMail(subject, context, SystemConstant.USERNAME.trim(), email);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void setMoblieMessage(String[] params,String context, String moblie,Integer shortId) {
        try{
            if(shortId !=0 &&moblie !=null&&moblie!=""){
//                context = contextRepalce(context,params);
                //发送手机短信
                SmsSendUtil.newInstance().send(moblie, shortId.toString(), params);
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /*** 商户商品被投诉提醒
     * @param o
     * @param complianId
     */
    public void sendComplainToStore(OrderVo o,Integer complianId){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("complain");
        Store store = storeMapper.selectStoreByPrimaryKey(o.getStoreId());
        Setting setting =settingMapper.selectByPrimaryKey("site_name");

        if(memberMsgTpl != null){
            if(memberMsgTpl.getMmtMessageSwitch() ==1 && memberMsgTpl.getMmtMessageContent() !=null){
                String[] str = new String[1];
                str[0] =complianId.toString();
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(store.getMemberId());
                toMember.setMemberName(store.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }

            if(memberMsgTpl.getMmtShortSwitch() ==1 && memberMsgTpl.getMmtShortContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                String[] str = new String[2];
                str[0] =setting.getValue().toString();
                str[1] =complianId.toString();
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }

            if(memberMsgTpl.getMmtMailSwitch() ==1 && memberMsgTpl.getMmtMailContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[4];
                    str[0] =setting.getValue().toString();
                    str[1] =complianId.toString();
                    str[2] =setting.getValue().toString();
                    str[3] =DateUtil.toTimeString(new Date());
                    String[] titles = new String[2];
                    titles[0] =setting.getValue().toString();
                    titles[1] =complianId.toString();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if(memberMsgTpl.getMmtWechatSwitch() ==1 && memberMsgTpl.getMmtWechatContent() !=null){
                String[] str = new String[2];
                str[0] =setting.getValue().toString();
                str[1] =complianId.toString();
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), store.getMemberId());
            }
        }
    }

    /***
     * 商户商品库存预警
     * @param goods
     */
    public void sendGoodsStorageAlarmToStore(Goods goods){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("goods_storage_alarm");
        Store store = storeMapper.selectStoreByPrimaryKey(goods.getStoreId());
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        String sku =goods.getGoodsId().toString();
        String goods_serial = goods.getGoodsSerial();
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[2];
                str[0] =goods_serial;
                str[1] =sku;
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(store.getMemberId());
                toMember.setMemberName(store.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if(memberMsgTpl.getMmtShortSwitch() ==1 && memberMsgTpl.getMmtShortContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                String[] str = new String[3];
                str[0] =setting.getValue();
                str[1] =goods_serial;
                str[2] =sku;
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if(memberMsgTpl.getMmtMailSwitch() ==1 && memberMsgTpl.getMmtMailContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    Setting pcwebsite =settingMapper.selectByPrimaryKey("site_name");
                    String[] str = new String[7];
                    str[0] =setting.getValue().toString();
                    str[1] =goods_serial;
                    str[2] =sku;
                    str[3] =pcwebsite.getValue();
                    str[4] =goods.getGoodsId().toString();
                    str[5] =setting.getValue().toString();
                    str[6] =DateUtil.toTimeString(new Date());
                    String[] titles = new String[1];
                    titles[0] =setting.getValue().toString();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if(memberMsgTpl.getMmtWechatSwitch() ==1 && memberMsgTpl.getMmtWechatContent() !=null){
                String[] str = new String[3];
                str[0] =setting.getValue();
                str[1] =goods_serial;
                str[2] =sku;
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), store.getMemberId());
            }
        }
    }

    /***
     * 商户商品审核失败提醒
     * @param goodsCommon
     */
    public void  sendGoodsVerifyToStore(GoodsCommon goodsCommon){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("goods_verify");
        Store store = storeMapper.selectStoreByPrimaryKey(goodsCommon.getStoreId());
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        String goods_serial = goodsCommon.getGoodsSerial();
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[2];
                str[0] ="不符合要求";
                str[1] =goods_serial;
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(store.getMemberId());
                toMember.setMemberName(store.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if(memberMsgTpl.getMmtShortSwitch() ==1 && memberMsgTpl.getMmtShortContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                String[] str = new String[3];
                str[0] =setting.getValue();
                str[1] ="不符合要求";
                str[2] =goods_serial;
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if(memberMsgTpl.getMmtMailSwitch() ==1 && memberMsgTpl.getMmtMailContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[5];
                    str[0] =setting.getValue();
                    str[1] ="不符合要求";
                    str[2] =goods_serial;
                    str[3] =setting.getValue();
                    str[4] =DateUtil.toTimeString(new Date());
                    String[] titles = new String[1];
                    titles[0] =setting.getValue().toString();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }

            }
            if(memberMsgTpl.getMmtWechatSwitch() ==1 && memberMsgTpl.getMmtWechatContent() !=null){
                String[] str = new String[3];
                str[0] =setting.getValue();
                str[1] ="不符合要求";
                str[2] =goods_serial;
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), store.getMemberId());
            }
        }
    }

    /***
     * 商户商品违规被下架
     * @param goodsCommon
     */
    public void sendGoodsViolationToStore(GoodsCommon goodsCommon){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("goods_violation");
        Store store = storeMapper.selectStoreByPrimaryKey(goodsCommon.getStoreId());
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        String goods_serial = goodsCommon.getGoodsSerial();
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[2];
                str[0] ="不符合要求";
                str[1] =goods_serial;
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(store.getMemberId());
                toMember.setMemberName(store.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if(memberMsgTpl.getMmtShortSwitch() ==1 && memberMsgTpl.getMmtShortContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                String[] str = new String[3];
                str[0] =setting.getValue();
                str[1] ="不符合要求";
                str[2] =goods_serial;
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if(memberMsgTpl.getMmtMailSwitch() ==1 && memberMsgTpl.getMmtMailContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[5];
                    str[0] =setting.getValue();
                    str[1] ="不符合要求";
                    str[2] =goods_serial;
                    str[3] =setting.getValue();
                    str[4] =DateUtil.toTimeString(new Date());
                    String[] titles = new String[1];
                    titles[0] =setting.getValue().toString();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if(memberMsgTpl.getMmtWechatSwitch() ==1 && memberMsgTpl.getMmtWechatContent() !=null){
                String[] str = new String[3];
                str[0] =setting.getValue();
                str[1] ="不符合要求";
                str[2] =goods_serial;
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), store.getMemberId());
            }

        }
    }

    /***
     * 商户新订单提醒
     * @param order
     */
    public void sendNewOrderToStore(Order order){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("goods_violation");
        Store store = storeMapper.selectStoreByPrimaryKey(order.getStoreId());
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[1];
                str[0] =order.getOrderSn().toString();
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(store.getMemberId());
                toMember.setMemberName(store.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if(memberMsgTpl.getMmtShortSwitch() ==1 && memberMsgTpl.getMmtShortContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                String[] str = new String[2];
                str[0] =setting.getValue();
                str[1] =order.getOrderSn().toString();
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if(memberMsgTpl.getMmtMailSwitch() ==1 && memberMsgTpl.getMmtMailContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[4];
                    str[0] =setting.getValue();
                    str[1] =order.getOrderSn().toString();
                    str[2] =setting.getValue();
                    str[3] =DateUtil.toTimeString(new Date());
                    String[] titles = new String[1];
                    titles[0] =setting.getValue().toString();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if(memberMsgTpl.getMmtWechatSwitch() ==1 && memberMsgTpl.getMmtWechatContent() !=null){
                String[] str = new String[2];
                str[0] =setting.getValue();
                str[1] =order.getOrderSn().toString();
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), store.getMemberId());
            }
        }
    }

    /****商户退款提醒
     * @param refund
     */
    public void sendRefundMoneyToStore(RefundReturn refund){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("goods_violation");
        Store store = storeMapper.selectStoreByPrimaryKey(refund.getStoreId());
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[1];
                str[0] =refund.getRefundSn();
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(store.getMemberId());
                toMember.setMemberName(store.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if(memberMsgTpl.getMmtShortSwitch() ==1 && memberMsgTpl.getMmtShortContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                String[] str = new String[2];
                str[0] =setting.getValue();
                str[1] =refund.getRefundSn();
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if(memberMsgTpl.getMmtMailSwitch() ==1 && memberMsgTpl.getMmtMailContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[4];
                    str[0] =setting.getValue();
                    str[1] =refund.getRefundSn();
                    str[2] =setting.getValue();
                    str[3] =DateUtil.toTimeString(new Date());
                    String[] titles = new String[2];
                    titles[0] =setting.getValue().toString();
                    titles[1] =refund.getRefundSn();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if(memberMsgTpl.getMmtWechatSwitch() ==1 && memberMsgTpl.getMmtWechatContent() !=null){
                String[] str = new String[2];
                str[0] =setting.getValue();
                str[1] =refund.getRefundSn();
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), store.getMemberId());
            }
        }
    }

    public void sendRefundGoodsToStore(RefundReturn refund){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("return");
        Store store = storeMapper.selectStoreByPrimaryKey(refund.getStoreId());
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[1];
                str[0] =refund.getRefundSn();
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(store.getMemberId());
                toMember.setMemberName(store.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if(memberMsgTpl.getMmtShortSwitch() ==1 && memberMsgTpl.getMmtShortContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                String[] str = new String[2];
                str[0] =setting.getValue();
                str[1] =refund.getRefundSn();
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if(memberMsgTpl.getMmtMailSwitch() ==1 && memberMsgTpl.getMmtMailContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[4];
                    str[0] =setting.getValue();
                    str[1] =refund.getRefundSn();
                    str[2] =setting.getValue();
                    str[3] =DateUtil.toTimeString(new Date());
                    String[] titles = new String[2];
                    titles[0] =setting.getValue().toString();
                    titles[1] =refund.getRefundSn();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if(memberMsgTpl.getMmtWechatSwitch() ==1 && memberMsgTpl.getMmtWechatContent() !=null){
                String[] str = new String[2];
                str[0] =setting.getValue();
                str[1] =refund.getRefundSn();
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), store.getMemberId());
            }
        }
    }
    /***
     * 商户店铺到期提醒
     * @param storeId
     */
    public void sendExpireToStore(Integer storeId){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("store_expire");
        Store store = storeMapper.selectStoreByPrimaryKey(storeId);
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[0];
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(store.getMemberId());
                toMember.setMemberName(store.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if(memberMsgTpl.getMmtShortSwitch() ==1 && memberMsgTpl.getMmtShortContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                String[] str = new String[1];
                str[0] =setting.getValue();
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if(memberMsgTpl.getMmtMailSwitch() ==1 && memberMsgTpl.getMmtMailContent() !=null){
                Member toMember = memberMapper.getMemberById(store.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[3];
                    str[0] =setting.getValue();
                    str[1] =setting.getValue();
                    str[2] =DateUtil.toTimeString(new Date());
                    String[] titles = new String[1];
                    titles[0] =setting.getValue().toString();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if(memberMsgTpl.getMmtWechatSwitch() ==1 && memberMsgTpl.getMmtWechatContent() !=null){
                String[] str = new String[1];
                str[0] =setting.getValue();
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), store.getMemberId());
            }
        }
    }

    /***
     * 到货提醒，针对用户
     */
    public void sendGoodsArrivalNoticeToUser(Goods goods){
    }

    /**
     * 商品咨询回复提醒
     * @param consult
     */
    public void sendConsultGoodsReplyToUser(Consult consult){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("consult_goods_reply");
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        Setting pcSite =settingMapper.selectByPrimaryKey("pcweb_site");
        String url =""+pcSite.getValue()+"/userCenter/consultList?searchType=revert";
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[2];
                str[0]=consult.getGoodsName();
                str[1]=url;
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(consult.getMemberId());
                toMember.setMemberName(consult.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if(memberMsgTpl.getMmtShortSwitch() ==1 && memberMsgTpl.getMmtShortContent() !=null){
                Member toMember = memberMapper.getMemberById(consult.getMemberId());
                String[] str = new String[2];
                str[0]=setting.getValue();
                str[1]=consult.getGoodsName();
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if(memberMsgTpl.getMmtMailSwitch() ==1 && memberMsgTpl.getMmtMailContent() !=null){
                Member toMember = memberMapper.getMemberById(consult.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[5];
                    str[0]=setting.getValue();
                    str[1]=consult.getGoodsName();
                    str[2]=url;
                    str[3]=setting.getValue();
                    str[4]=DateUtil.toTimeString(new Date());
                    String[] titles = new String[2];
                    titles[0]=setting.getValue();
                    titles[1]=consult.getGoodsName();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if(memberMsgTpl.getMmtWechatSwitch() ==1 && memberMsgTpl.getMmtWechatContent() !=null){
                String[] str = new String[2];
                str[0]=setting.getValue();
                str[1]=consult.getGoodsName();
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), consult.getMemberId());
            }
        }
    }
    /***
     * 商品出库提醒
     * @param order
     */
    public void orderDeliverSuccessToUser(Order order){
        try{
            MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("order_deliver_success");
            Setting setting =settingMapper.selectByPrimaryKey("site_name");
            Setting pcSite =settingMapper.selectByPrimaryKey("pcweb_site");
            String url =""+pcSite.getValue()+"/userCenter/orderList?orderSn="+order.getOrderSn();
            if(memberMsgTpl != null) {
                if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                    String[] str = new String[1];
                    str[0]=url;
                    Member fromMember = new Member();
                    fromMember.setMemberId(0);
                    fromMember.setMemberName("system");
                    Member toMember = new Member();
                    toMember.setMemberId(order.getBuyerId());
                    toMember.setMemberName(order.getBuyerName());
                    this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
                }
                if (memberMsgTpl.getMmtShortSwitch() == 1 && memberMsgTpl.getMmtShortContent() != null) {
                    Member toMember = memberMapper.getMemberById(order.getBuyerId());
                    String[] str = new String[2];
                    str[0]=setting.getValue();
                    str[1]=order.getOrderSn().toString();
                    this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
                }
                if (memberMsgTpl.getMmtMailSwitch() == 1 && memberMsgTpl.getMmtMailContent() != null) {
                    Member toMember = memberMapper.getMemberById(order.getBuyerId());
                    if(toMember.getMemberEmail()!= null){
                        String[] str = new String[5];
                        str[0]=setting.getValue();
                        str[1]=order.getOrderSn().toString();
                        str[2]=url;
                        str[3]=setting.getValue();
                        str[4]=DateUtil.toTimeString(new Date());
                        String[] titles = new String[2];
                        titles[0]=setting.getValue();
                        titles[1]=order.getOrderSn().toString();
                        this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                    }
                }
                if (memberMsgTpl.getMmtWechatSwitch() == 1 && memberMsgTpl.getMmtWechatContent() != null) {
                    String[] str = new String[2];
                    str[0]=setting.getValue();
                    str[1]=order.getOrderSn().toString();
                    this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), order.getBuyerId());
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    /***
     * 付款成功提醒
     * @param order
     */
    public void  orderPaymentSuccessToUser(Order order){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("order_payment_success");
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        Setting pcSite =settingMapper.selectByPrimaryKey("pcweb_site");
        String url =""+pcSite.getValue()+"/userCenter/orderList?orderSn="+order.getOrderSn();
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[1];
                str[0]=url;
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(order.getBuyerId());
                toMember.setMemberName(order.getBuyerName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if (memberMsgTpl.getMmtShortSwitch() == 1 && memberMsgTpl.getMmtShortContent() != null) {
                Member toMember = memberMapper.getMemberById(order.getBuyerId());
                String[] str = new String[2];
                str[0]=setting.getValue();
                str[1]=order.getOrderSn().toString();
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(),toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if (memberMsgTpl.getMmtMailSwitch() == 1 && memberMsgTpl.getMmtMailContent() != null) {
                Member toMember = memberMapper.getMemberById(order.getBuyerId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[5];
                    str[0]=setting.getValue();
                    str[1]=order.getOrderSn().toString();
                    str[2]=url;
                    str[3]=setting.getValue();
                    str[4]=DateUtil.toTimeString(new Date());
                    String[] titles = new String[2];
                    titles[0]=setting.getValue();
                    titles[1]=order.getOrderSn().toString();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if (memberMsgTpl.getMmtWechatSwitch() == 1 && memberMsgTpl.getMmtWechatContent() != null) {
                String[] str = new String[2];
                str[0]=setting.getValue();
                str[1]=order.getOrderSn().toString();
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), order.getBuyerId());
            }
        }
    }

    /***
     * 余额变动提醒
     * @param pdLog
     */
    public void  sendPredepositChangeToUser(PdLog pdLog){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("predeposit_change");
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        Setting pcSite =settingMapper.selectByPrimaryKey("pcweb_site");
        String url =""+pcSite.getValue()+"/userCenter/logList";
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[5];
                str[0] = DateUtil.toTimeString(new Date());
                str[1] = pdLog.getLgDesc();
                str[2] = pdLog.getLgAvAmount()!=null?pdLog.getLgAvAmount().toString():"0";
                str[3] = pdLog.getLgFreezeAmount()!=null?pdLog.getLgFreezeAmount().toString():"0";
                str[4] = url;
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(pdLog.getLgMemberId());
                toMember.setMemberName(pdLog.getLgMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if (memberMsgTpl.getMmtShortSwitch() == 1 && memberMsgTpl.getMmtShortContent() != null) {
                Member toMember = memberMapper.getMemberById(pdLog.getLgMemberId());
                String[] str = new String[6];
                str[0] = setting.getValue();
                str[1] = DateUtil.toTimeString(new Date());
                str[2] = pdLog.getLgDesc();
                str[3] = pdLog.getLgAvAmount()!=null?pdLog.getLgAvAmount().toString():"0";
                str[4] = pdLog.getLgFreezeAmount()!=null?pdLog.getLgFreezeAmount().toString():"0";
                str[5] = url;
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if (memberMsgTpl.getMmtWechatSwitch() == 1 && memberMsgTpl.getMmtWechatContent() != null) {
                String[] str = new String[6];
                str[0] = setting.getValue();
                str[1] = DateUtil.toTimeString(new Date());
                str[2] = pdLog.getLgDesc();
                str[3] = pdLog.getLgAvAmount()!=null?pdLog.getLgAvAmount().toString():"0";
                str[4] = pdLog.getLgFreezeAmount()!=null?pdLog.getLgFreezeAmount().toString():"0";
                str[5] = url;
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), pdLog.getLgMemberId());
            }
        }
    }

    public void sendRefundReturnNoticeToUser(RefundReturn refund){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("refund_return_notice");
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        Setting pcSite =settingMapper.selectByPrimaryKey("pcweb_site");
        String url =""+pcSite.getValue()+"/userCenter/moneyList";
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[1];
                str[0] =url;
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(refund.getBuyerId());
                toMember.setMemberName(refund.getBuyerName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if(memberMsgTpl.getMmtShortSwitch() ==1 && memberMsgTpl.getMmtShortContent() !=null){
                Member toMember = memberMapper.getMemberById(refund.getBuyerId());
                String[] str = new String[2];
                str[0] =setting.getValue();
                str[1] =refund.getRefundSn();
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(), memberMsgTpl.getMmtShortId());
            }
            if(memberMsgTpl.getMmtMailSwitch() ==1 && memberMsgTpl.getMmtMailContent() !=null){
                Member toMember = memberMapper.getMemberById(refund.getBuyerId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[5];
                    str[0] =setting.getValue();
                    str[1] =refund.getRefundSn();
                    str[2] =url;
                    str[3] =setting.getValue();
                    str[4] =DateUtil.toTimeString(new Date());
                    String[] titles = new String[1];
                    titles[0] = setting.getValue();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if(memberMsgTpl.getMmtWechatSwitch() ==1 && memberMsgTpl.getMmtWechatContent() !=null){
                String[] str = new String[2];
                str[0] =setting.getValue();
                str[1] =refund.getRefundSn();
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), refund.getBuyerId());
            }
        }
    }

    /***
     * 代金券使用提醒
     * @param voucher
     */
    public void sendVoucherUseToUser(Voucher voucher){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("voucher_use");
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        Setting pcSite =settingMapper.selectByPrimaryKey("pcweb_site");
        String url =""+pcSite.getValue()+"/userCenter/voucherList";
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[2];
                str[0] =voucher.getVoucherCode();
                str[1] =url;
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(voucher.getVoucherOwnerId());
                toMember.setMemberName(voucher.getVoucherOwnerName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if(memberMsgTpl.getMmtShortSwitch() ==1 && memberMsgTpl.getMmtShortContent() !=null){
                Member toMember = memberMapper.getMemberById(voucher.getVoucherOwnerId());
                String[] str = new String[2];
                str[0] = setting.getValue();
                str[1] = voucher.getVoucherCode();
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if(memberMsgTpl.getMmtMailSwitch() ==1 && memberMsgTpl.getMmtMailContent() !=null){
                Member toMember = memberMapper.getMemberById(voucher.getVoucherOwnerId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[5];
                    str[0] =setting.getValue();
                    str[1] =voucher.getVoucherCode();
                    str[2] =url;
                    str[3] =setting.getValue();
                    str[4] =DateUtil.toTimeString(new Date());
                    String[] titles = new String[2];
                    titles[0] =setting.getValue();
                    titles[1] =voucher.getVoucherCode();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if(memberMsgTpl.getMmtWechatSwitch() ==1 && memberMsgTpl.getMmtWechatContent() !=null){
                String[] str = new String[2];
                str[0] =setting.getValue();
                str[1] =voucher.getVoucherCode();
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), voucher.getVoucherOwnerId());
            }
        }
    }
    public void sendVoucherWillExpireToUser(Voucher voucher){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("voucher_will_expire");
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        Setting pcSite =settingMapper.selectByPrimaryKey("pcweb_site");
        String url =""+pcSite.getValue()+"/userCenter/voucherList";
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[2];
                str[0] =DateUtil.toIntDate(voucher.getVoucherEndDate()).toString();
                str[1] =url;
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(voucher.getVoucherOwnerId());
                toMember.setMemberName(voucher.getVoucherOwnerName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if (memberMsgTpl.getMmtShortSwitch() == 1 && memberMsgTpl.getMmtShortContent() != null) {
                Member toMember = memberMapper.getMemberById(voucher.getVoucherOwnerId());
                String[] str = new String[2];
                str[0] = setting.getValue();
                str[1] = DateUtil.toIntDate(voucher.getVoucherEndDate()).toString();
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if (memberMsgTpl.getMmtMailSwitch() == 1 && memberMsgTpl.getMmtMailContent() != null) {
                Member toMember = memberMapper.getMemberById(voucher.getVoucherOwnerId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[5];
                    str[0] =setting.getValue();
                    str[1] =DateUtil.toIntDate(voucher.getVoucherEndDate()).toString();
                    str[2] =url;
                    str[3] =setting.getValue();
                    str[4] =DateUtil.toTimeString(new Date());
                    String[] titles = new String[2];
                    titles[0] =setting.getValue();
                    titles[1] =DateUtil.toIntDate(voucher.getVoucherEndDate()).toString();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if (memberMsgTpl.getMmtWechatSwitch() == 1 && memberMsgTpl.getMmtWechatContent() != null) {
                String[] str = new String[2];
                str[0] = setting.getValue();
                str[1] = DateUtil.toIntDate(voucher.getVoucherEndDate()).toString();
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), voucher.getVoucherOwnerId());
            }
        }
    }

    /***
     * 身份验证通知
     * @param member
     */
    public void sendAuthenticate(Member member,String code){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("authenticate");
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        Setting pcSite =settingMapper.selectByPrimaryKey("pcweb_site");
        String url =""+pcSite.getValue()+"/userCenter/voucherList";
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[2];
                str[0] =DateUtil.toTimeString(new Date());
                str[1] =code;
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(member.getMemberId());
                toMember.setMemberName(member.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if (memberMsgTpl.getMmtShortSwitch() == 1 && memberMsgTpl.getMmtShortContent() != null) {
                Member toMember = memberMapper.getMemberById(member.getMemberId());
                String[] str = new String[3];
                str[0] = setting.getValue();
                str[1] =DateUtil.toTimeString(new Date());
                str[2] =code;
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if (memberMsgTpl.getMmtMailSwitch() == 1 && memberMsgTpl.getMmtMailContent() != null) {
                Member toMember = memberMapper.getMemberById(member.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[3];
                    str[0] = setting.getValue();
                    str[1] =DateUtil.toTimeString(new Date());
                    str[2] =code;
                    String[] titles = new String[1];
                    titles[0] =setting.getValue();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if (memberMsgTpl.getMmtWechatSwitch() == 1 && memberMsgTpl.getMmtWechatContent() != null) {
                String[] str = new String[3];
                str[0] = setting.getValue();
                str[1] =DateUtil.toTimeString(new Date());
                str[2] =code;
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), member.getMemberId());
            }
        }
    };

    /***
     * 邮箱验证通知
     * @param member
     */
    public void sendBindEmail(Member member,String code){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("authenticate");
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        Setting pcSite =settingMapper.selectByPrimaryKey("pcweb_site");
        String url =""+pcSite.getValue()+"/userCenter/voucherList";
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[1];
                str[0] = setting.getValue();
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(member.getMemberId());
                toMember.setMemberName(member.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if (memberMsgTpl.getMmtShortSwitch() == 1 && memberMsgTpl.getMmtShortContent() != null) {
                Member toMember = memberMapper.getMemberById(member.getMemberId());
                String[] str = new String[1];
                str[0] = setting.getValue();
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if (memberMsgTpl.getMmtMailSwitch() == 1 && memberMsgTpl.getMmtMailContent() != null) {
                Member toMember = memberMapper.getMemberById(member.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[2];
                    str[0] = url;
                    str[1] =url;
                    String[] titles = new String[1];
                    titles[0] =setting.getValue();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if (memberMsgTpl.getMmtWechatSwitch() == 1 && memberMsgTpl.getMmtWechatContent() != null) {
                String[] str = new String[1];
                str[0] = setting.getValue();
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), member.getMemberId());
            }
        }
    };
    /***
     * 手机验证通知
     * @param member
     */
    public void sendModifyMobile(Member member,String code){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("authenticate");
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        Setting pcSite =settingMapper.selectByPrimaryKey("pcweb_site");
        String url =""+pcSite.getValue()+"/userCenter/voucherList";
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[1];
                str[0] = DateUtil.toTimeString(new Date());
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(member.getMemberId());
                toMember.setMemberName(member.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if (memberMsgTpl.getMmtShortSwitch() == 1 && memberMsgTpl.getMmtShortContent() != null) {
                Member toMember = memberMapper.getMemberById(member.getMemberId());
                String[] str = new String[2];
                str[0] = setting.getValue();
                str[1] = DateUtil.toTimeString(new Date());
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if (memberMsgTpl.getMmtMailSwitch() == 1 && memberMsgTpl.getMmtMailContent() != null) {
                Member toMember = memberMapper.getMemberById(member.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[3];
                    str[0] = setting.getValue();
                    str[1] = DateUtil.toTimeString(new Date());
                    str[2] = code;
                    String[] titles = new String[1];
                    titles[0] =setting.getValue();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if (memberMsgTpl.getMmtWechatSwitch() == 1 && memberMsgTpl.getMmtWechatContent() != null) {
                String[] str = new String[2];
                str[0] = setting.getValue();
                str[1] = DateUtil.toTimeString(new Date());
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), member.getMemberId());
            }
        }
    };
    /***
     * 重置密码通知
     * @param member
     */
    public void sendResetPwd(Member member,String code){
        MemberMsgTpl memberMsgTpl=memberMsgTplMapper.selectByPrimaryKey("authenticate");
        Setting setting =settingMapper.selectByPrimaryKey("site_name");
        Setting pcSite =settingMapper.selectByPrimaryKey("pcweb_site");
        String url =""+pcSite.getValue()+"/userCenter/voucherList";
        if(memberMsgTpl != null) {
            if (memberMsgTpl.getMmtMessageSwitch() == 1 && memberMsgTpl.getMmtMessageContent() != null) {
                String[] str = new String[0];
                Member fromMember = new Member();
                fromMember.setMemberId(0);
                fromMember.setMemberName("system");
                Member toMember = new Member();
                toMember.setMemberId(member.getMemberId());
                toMember.setMemberName(member.getMemberName());
                this.setInnerMessage(str, 1, memberMsgTpl.getMmtMessageContent(), fromMember, toMember);
            }
            if (memberMsgTpl.getMmtShortSwitch() == 1 && memberMsgTpl.getMmtShortContent() != null) {
                Member toMember = memberMapper.getMemberById(member.getMemberId());
                String[] str = new String[2];
                str[0] = setting.getValue();
                str[1] = code;
                this.setMoblieMessage(str, memberMsgTpl.getMmtShortContent(), toMember.getMemberMobile(),memberMsgTpl.getMmtShortId());
            }
            if (memberMsgTpl.getMmtMailSwitch() == 1 && memberMsgTpl.getMmtMailContent() != null) {
                Member toMember = memberMapper.getMemberById(member.getMemberId());
                if(toMember.getMemberEmail()!= null){
                    String[] str = new String[2];
                    str[0] = code;
                    str[1] = url;
                    String[] titles = new String[1];
                    titles[0] =setting.getValue();
                    this.setMailMessage(titles,str, memberMsgTpl.getMmtMailSubject(), memberMsgTpl.getMmtMailContent(), toMember.getMemberEmail());
                }
            }
            if (memberMsgTpl.getMmtWechatSwitch() == 1 && memberMsgTpl.getMmtWechatContent() != null) {
                String[] str = new String[2];
                str[0] = setting.getValue();
                str[1] = code;
                this.setWXMessage(str, memberMsgTpl.getMmtWechatContent(), member.getMemberId());
            }
        }
    }
}
